<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        li {
            list-style: none;
        }

        .menu {
            width: 1000px;
            height: 100px;
        }

        .menu>li {
            width: 200px;
            float: left;
            position: relative;
        }

        .submenu {
            position: absolute;
            left: -40px;

        }

        .submenu {
            display: none;
        }

        .current {
            display: block;
        }
    </style>
</head>

<body>
    <ul class="menu">
        <li>
            <a href="#">首页</a>
            <ul class="submenu">
                <li>子菜单一</li>
                <li>子菜单一</li>
                <li>子菜单一</li>
            </ul>
        </li>
        <li>
            <a href="#">新闻</a>
            <ul class="submenu">
                <li>子菜单一</li>
                <li>子菜单一</li>
                <li>子菜单一</li>
            </ul>
        </li>
        <li>
            <a href="#">动态</a>
            <ul class="submenu">
                <li>子菜单一</li>
                <li>子菜单一</li>
                <li>子菜单一</li>
            </ul>
        </li>
    </ul>
    <script>
        var lis = document.querySelectorAll(".menu >li");
        var submenu = document.querySelectorAll(".submenu");
        console.log(submenu);
        for (let i = 0; i < lis.length; i++) {
            lis[i].addEventListener("mouseover", function () {
                for (let i = 0; i < lis.length; i++) {
                    submenu[i].className = "submenu";
                }
                submenu[i].className = "submenu current";
            })
            lis[i].addEventListener("mouseout", function () {
                submenu[i].className = "submenu";
            })
        }
    </script>
</body>

</html>